<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>分类管理</title>
    <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css" rel="stylesheet"/>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@500&display=swap" rel="stylesheet" />
    <style>
        /* Labubu风格颜色变量 */
        :root {
            --primary: #FF6B9B;     /* Labubu主色调：粉色 */
            --secondary: #9A7DFF;   /* Labubu辅助色：紫色 */
            --accent: #FFD166;      /* Labubu强调色：黄色 */
            --bg-light: #FFF5F8;    /* Labubu浅色背景 */
            --bg-dark: #FFFFFF;     /* 深色背景 */
            --text-dark: #5A5A5A;   /* 文本颜色 */
        }

        body {
            background: var(--bg-light);
            font-family: 'Orbitron', sans-serif;
            color: var(--text-dark);
            margin: 0;
            padding: 0;
        }

        .container {
            width: 95%;
            margin: 40px auto;
        }

        .navbar {
            background-color: var(--bg-dark);
            padding: 15px 30px;
            display: flex;
            justify-content: center;
            gap: 30px;
            box-shadow: 0 0 10px var(--primary);
        }

        .navbar a {
            color: var(--primary);
            text-decoration: none;
            font-size: 16px;
            letter-spacing: 1px;
        }

        .navbar a:hover {
            text-shadow: 0 0 10px var(--primary);
        }

        h2 {
            text-align: center;
            color: var(--primary);
            text-shadow: 0 0 5px var(--primary);
            margin-bottom: 20px;
        }

        .add-btn {
            display: inline-block;
            padding: 10px 20px;
            background: transparent;
            border: 2px solid var(--primary);
            color: var(--primary);
            border-radius: 6px;
            margin-bottom: 20px;
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .add-btn:hover {
            background: var(--primary);
            color: white;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            background: var(--bg-dark);
            box-shadow: 0 0 15px var(--primary);
        }

        th, td {
            padding: 12px;
            border: 1px solid var(--primary);
            text-align: center;
            vertical-align: middle;
        }

        th {
            background-color: #F5F5F5;
            color: var(--primary);
        }

        tr:hover {
            background-color: #F0F0F0;
        }

        a.action-link {
            color: var(--primary);
            text-decoration: none;
            margin: 0 5px;
        }

        a.action-link:hover {
            text-shadow: 0 0 5px var(--primary);
        }
    </style>
</head>
<body>
<div class="navbar">
    <a href="${pageContext.request.contextPath}/goods/list">🧸 商品管理</a>
    <a href="${pageContext.request.contextPath}/category/list">📁 分类管理</a>
    <a href="${pageContext.request.contextPath}/order/list">📦 订单管理</a>
    <a href="${pageContext.request.contextPath}/user/list">👤 用户管理</a>
    <a href="${pageContext.request.contextPath}/user/logout">🚪 退出登录</a>
</div>

<div class="container">
    <h2>分类管理</h2>
    <a href="${pageContext.request.contextPath}/category/addForm" class="add-btn">➕ 添加新分类</a>
    <table>
        <tr>
            <th>分类ID</th>
            <th>标题</th>
            <th>分类名</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <c:forEach var="category" items="${categories}">
            <tr>
                <td>${category.cid}</td>
                <td>${category.title}</td>
                <td>
                    <c:choose>
                        <c:when test="${category.pid == 0}">
                            顶级分类
                        </c:when>
                        <c:otherwise>
                            ${categoryTitleMap[category.pid]}
                        </c:otherwise>
                    </c:choose>
                </td>
                <td>
                    <c:choose>
                        <c:when test="${category.state == 1}">启用</c:when>
                        <c:otherwise>禁用</c:otherwise>
                    </c:choose>
                </td>
                <td>
                    <a href="${pageContext.request.contextPath}/category/editForm/${category.cid}" class="action-link">编辑</a> |
                    <a href="${pageContext.request.contextPath}/category/delete/${category.cid}" class="action-link"
                       onclick="return confirm('确定删除该分类吗？');">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
</body>
</html>